<template>
  <div class="wx_input_content">
    <span class="wx_input input--nao">
      <input :type="datas.type" ref="wx_input_need" class="input__field input__field--nao" :id="datas.id" @blur="checkValue"/>
      <label class="input__label input__label--nao" :for="datas.id">
        <span class="input__label-content input__label-content--nao">{{datas.label}}</span>
      </label>
      <svg class="graphic graphic--nao" width="300%" height="100%" viewBox="0 0 1200 60" preserveAspectRatio="none">
        <path
          d="M0,56.5c0,0,298.666,0,399.333,0C448.336,56.5,513.994,46,597,46c77.327,0,135,10.5,200.999,10.5c95.996,0,402.001,0,402.001,0"/>
      </svg>
    </span>
  </div>
</template>

<script>
export default {
  name: 'wx-input',
  props: {
    datas: {
      type: Object,
      default: () => {
        return {
          label: 'username',
          type: 'text',
          id: 'username'
        }
      }
    }
  },
  mounted () {
    this.listenInputBlur()
  },
  methods: {
    listenInputBlur () { // 监听是否输入
      let Input = this.$refs.wx_input_need
      Input.onblur = function () {
        let label = this.parentNode.childNodes[2]
        if (!this.value) {
          label.style.display = 'block'
        } else {
          label.style.display = 'none'
        }
      }
    },
    checkValue () {
      this.$emit('getValues', this.$refs.wx_input_need.value)
    }
  }
}
</script>

<style scoped>
  .wx_input_content{
    text-align: center;
  }
  .wx_input {
    position: relative;
    z-index: 1;
    display: inline-block;
    margin: 1em;
    max-width: 350px;
    width: calc(100% - 2em);
    vertical-align: top;
  }

  .input__field {
    position: relative;
    display: block;
    float: right;
    padding: 0.8em;
    width: 60%;
    border: none;
    border-radius: 0;
    background: #f0f0f0;
    color: #aaa;
    font-weight: 400;
    -webkit-appearance: none; /* for box shadows to show on iOS */
  }

  .input__field:focus {
    outline: none;
  }

  .input__label {
    display: inline-block;
    float: right;
    padding: 0 1em;
    width: 40%;
    color: #696969;
    font-weight: bold;
    font-size: 70.25%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
  }

  .input__label-content {
    position: relative;
    display: block;
    padding: 1.6em 0;
    width: 100%;
    letter-spacing: 3px;
  }

  .graphic {
    position: absolute;
    top: 0;
    left: 0;
    fill: none;
  }

  .input--nao {
    overflow: hidden;
    padding-top: 2em;
  }

  .input__field--nao {
    padding: 0.5em 0em 0.25em;
    width: 100%;
    background: transparent;
    color: #000000;
    font-size: 1.25em;
    letter-spacing: 2px;
  }

  .input__label--nao {
    position: absolute;
    top: 0.95em;
    font-size: 0.85em;
    left: 0;
    display: block;
    width: 100%;
    text-align: left;
    padding: 0em;
    pointer-events: none;
    -webkit-transform-origin: 0 0;
    transform-origin: 0 0;
    -webkit-transition: -webkit-transform 0.2s 0.15s, color 1s;
    transition: transform 0.2s 0.15s, color 1s;
    -webkit-transition-timing-function: ease-out;
    transition-timing-function: ease-out;
  }

  .graphic--nao {
    stroke: #92989e;
    pointer-events: none;
    -webkit-transition: -webkit-transform 0.7s, stroke 0.7s;
    transition: transform 0.7s, stroke 0.7s;
    -webkit-transition-timing-function: cubic-bezier(0, 0.25, 0.5, 1);
    transition-timing-function: cubic-bezier(0, 0.25, 0.5, 1);
  }

  .input__field--nao:focus + .input__label--nao,
  .input--filled .input__label--nao {
    color: #333;
    -webkit-transform: translate3d(0, -1.25em, 0) scale3d(0.75, 0.75, 1);
    transform: translate3d(0, -1.25em, 0) scale3d(0.75, 0.75, 1);
  }

  .input__field--nao:focus ~ .graphic--nao,
  .input--filled .graphic--nao {
    stroke: #333;
    -webkit-transform: translate3d(-66.6%, 0, 0);
    transform: translate3d(-66.6%, 0, 0);
  }
</style>
